﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace App16._5
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        public void OnLoaded(object sender, RoutedEventArgs args)
        {
            AdornerLayer layer = AdornerLayer.GetAdornerLayer(label);
            layer.Add(new MidLineAdorner(label));

            //
            
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {

        }

        private void button1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            
        }
    }

    public class MidLineAdorner : Adorner
    {
        public MidLineAdorner(UIElement adornedElement)
            : base(adornedElement)
        {
        }

        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);

            Rect rect = new Rect(AdornedElement.DesiredSize);

            drawingContext.DrawLine(new Pen(Brushes.Black, 1),
                new Point(rect.Left, (rect.Top + rect.Bottom) / 2),
                new Point(rect.Right, (rect.Top + rect.Bottom) / 2));
        }
    }
}
